package com.wd.live.module_login.view.fragment


import android.view.View
import android.widget.Toast
import androidx.fragment.app.Fragment
import com.wd.live.module_base.ui.base.BaseFragment
import com.wd.live.module_login.R
import com.wd.live.module_login.databinding.FragmentGenderBinding
import com.wd.live.module_login.databinding.FragmentGenderBindingImpl
import com.wd.live.module_login.viewmodel.ReversoContextViewModel


// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private const val ARG_PARAM1 = "param1"
private const val ARG_PARAM2 = "param2"

/**
 * A simple [Fragment] subclass.
 * Use the [GenderFragment.newInstance] factory method to
 * create an instance of this fragment.性别
 *
 */
class GenderFragment : BaseFragment<ReversoContextViewModel, FragmentGenderBinding>() {
//    性别 男传1，女传2
    val nan:Int=1
    val nv:Int=2
    var currentSelected:Int=0
    override fun initData() {
        dataBinding.genderNv.setOnClickListener(View.OnClickListener {
            genderSelect(nv)
        })
        dataBinding.genderNan.setOnClickListener(View.OnClickListener {
            genderSelect(nan)
        })
        genderSelect(0)
    }
    //选中切换状态
    fun genderSelect(type:Int){
        when(type){
            1->{
                dataBinding.genderNv.isSelected=false
                dataBinding.genderNan.isSelected=true
                currentSelected=nan
                genderModify(currentSelected)
            }
            2->{
                dataBinding.genderNv.isSelected=true
                dataBinding.genderNan.isSelected=false
                currentSelected=nv
                genderModify(currentSelected)
            }
        }
    }

    fun genderModify(currentSelected:Int){
        viewModel.putModifySex(currentSelected)
        viewModel.dataModifySex.observe(this){
            Toast.makeText(context,it.message,Toast.LENGTH_SHORT).show()
        }

    }
    override fun getViewModelClass(): Class<ReversoContextViewModel> {
        return ReversoContextViewModel::class.java
    }

    override fun getLayout(): Int {
        return R.layout.fragment_gender
    }

}